--money.lua
--Adds methods to Player object for manipulating money

local playermt = FindMetaTable("Player")

function playermt:GetWallet()
	return self:GetNetworkedInt("wallet")
end

function playermt:SetWallet(value)
	self:SetNetworkedInt("wallet", value)
	self:SaveWallet()
end

function playermt:SaveWallet()
	self:SetPData("wallet", self:GetWallet())
end

function playermt:LoadWallet()	
	if not self:GetPData("wallet") then
		self:SetPData("wallet", STARTING_MONEY)
	end
	self:SetWallet(self:GetPData("wallet"))
end

hook.Add("PlayerInitialSpawn", "firstSpawnWalletLoad", function(plr)
	plr:LoadWallet()
end)
hook.Add("PlayerDisconnected", "disconnectWalletSave", function(plr)		--TODO: Is this necessary? Any calls to SetMoney(value) should call SaveMoney() automatically
	plr:SaveWallet()
end)
